package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.UserDao;
import org.example.domain.UserDO;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, UserDO> implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public List<UserDO> pagelist(int current, int size, Wrapper<UserDO>queryWrapper) {
        Page<UserDO> page =new Page<>();
        page.setCurrent(current);
        page.setSize(size);
        return    userDao.selectPage(page, queryWrapper).getRecords();
    }

    @Override
    @Transactional
    public int updateUser(UserDO userDO) {
        return userDao.updateUser(userDO);
    }


    @Override
    public int insertUser(UserDO userDO) {
        return userDao.insert(userDO);
    }

    @Override
    public int deleteUser(UserDO userDO) {
        return userDao.deleteById(userDO.getUserId());
    }
}
